package com.cheng.example.easypoi.charper01.j01;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 动态导入测试
 *
 */
public class Test01 {

    @SneakyThrows
    public static void main(String[] args) {
        List<ExcelExportEntity> headList = new ArrayList<ExcelExportEntity>();

        ExcelExportEntity entity1 =new ExcelExportEntity("姓名", "name");
        entity1.setMergeVertical(true);
        headList.add(entity1);

        headList.add(new ExcelExportEntity(null, "signIn"));
        headList.add(new ExcelExportEntity("12/16", "16"));

        ExcelExportEntity outEntity= new ExcelExportEntity("出差", "out");
        outEntity.setMergeVertical(true);
        outEntity.setWidth(4);
        headList.add(outEntity);

        ExcelExportEntity leaveEntity= new ExcelExportEntity("请假", "leave");
        leaveEntity.setMergeVertical(true);
        leaveEntity.setWidth(4);
        headList.add(leaveEntity);

        ExcelExportEntity lateEntity = new ExcelExportEntity("漏刷/迟到/早退", "late");
        lateEntity.setMergeVertical(true);
        lateEntity.setWidth(15);
        headList.add(lateEntity);

        List<Map<String, Object>> bodyMapList = new ArrayList<Map<String, Object>>();

        Map map = new HashMap<>();
        map.put("name", "王晓\n敏");
        map.put("signIn", "签到");
        map.put("16", "7:46");
        map.put("out", "1");
        map.put("leave", " ");
        map.put("late", " ");


        Map map1 = new HashMap<>();
        map1.put("name", "王晓\n敏");
        map1.put("signIn", "签退");
        map1.put("16", "16:46");
        map1.put("out", "1");
        map1.put("leave", " ");
        map1.put("late", " ");

        bodyMapList.add(map);
        bodyMapList.add(map1);

        ExportParams params = new ExportParams("2019年12月16日-27日考勤情况表", "我是sheet");
//        params.setTitleHeight((short) 30);
//        params.setTitleHeight((short) 30);
        params.setColor((short) 15);
//        params.setStyle(ExcelExportStylerBorderImpl.class);

        params.setStyle(TestExportStyler.class);
//        params.setHeaderColor((short) 41);

        Workbook workbook = ExcelExportUtil.exportExcel(params, headList, bodyMapList);

        File file = new File("D:/home/excel/v1");

        if (!file.exists()) {
            file.mkdirs();
        }

        FileOutputStream fos = new FileOutputStream("D:/home/excel/v1/ExcelExportForMap1.tt.xls");
        workbook.write(fos);
        fos.close();
    }

}
